import { Component, OnInit, Injector, Output, EventEmitter } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ServiceProxy, WarnInfoDTO } from '@shared/service-proxy/service-proxies';

@Component({
  selector: 'app-report-warn-modal',
  templateUrl: './report-warn-modal.component.html',
  styleUrls: ['./report-warn-modal.component.less']
})
export class ReportWarnModalComponent extends AppComponentBase implements OnInit {
  @Output() modalSave = new EventEmitter<any>();
  isVisible: boolean = false;
  isOkLoading: boolean = false;
  handlereport: string;
  warnInfo = new WarnInfoDTO();

  constructor(injector: Injector,
    private _service: ServiceProxy) {
    super(injector);
  }

  ngOnInit() {

  }


  show(id: string,report?:string) {
    this.isVisible = true;
    this.warnInfo.id = id;
    this.warnInfo.handlereport = report;
  }

  handleOk() {
    this.isOkLoading = true;
    this._service.updateWarnInfoHandleUsingPUT(this.warnInfo, this.warnInfo.id).subscribe(result => {
      this.message.info(this.l('save_success'));
      this.modalSave.emit();
      this.isOkLoading = false;
      this.isVisible = false;
    }, error => {
      this.message.error(error.error);
      this.isOkLoading = false;
    });
  }

  handleCancel() {
    this.isVisible = false;
  }
}
